package joSaysHello.server;

import java.io.IOException;
import java.io.PrintWriter;

import javax.jdo.PersistenceManager;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import joSaysHello.shared.entity.User;

public class LoginStatus extends HttpServlet {

	private static final long serialVersionUID = -5881664103674680809L;

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		PrintWriter out = resp.getWriter();
		PersistenceManager pm = PMFSingleton.getPM();
		User user = UserManager.getCurrentUser(pm);
		resp.setContentType("text/html");
		out.println("<div width='100%' height='100%' align='center' valign='middle'>");
		if(user == null)
			out.println("You are so not logged in dude.");
		else
			out.println("You are logged in as "+user.getNickname()+" now.");
		out.println("</div>");
		pm.close();
	}
}
